package com.haelth.view;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import com.haelth.control.ChahwaGetQuery;
import com.haelth.control.HealthMutilQuery;
import com.haelth.control.HealthOneQuery;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ChahwaQuery {

	private JFrame frame;
	private JTextField QueryTxt;
	private static JTextArea Resault = new JTextArea();
	int ret = 1;
	JFileChooser fc = new JFileChooser();
	private File obj;
	private JTextField QueryChinese;

	/**
	 * Create the application.
	 */
	public ChahwaQuery() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setTitle("嘉鏵藥品查詢");
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		frame.setResizable(false);
		frame.setVisible(true);
		JLabel lblNewLabel = new JLabel("健保碼：");
		lblNewLabel.setFont(new Font("PMingLiU", Font.PLAIN, 12));
		lblNewLabel.setBounds(10, 20, 68, 15);
		frame.getContentPane().add(lblNewLabel);
		QueryTxt = new JTextField();
		QueryTxt.setBounds(78, 17, 179, 21);
		frame.getContentPane().add(QueryTxt);
		QueryTxt.setColumns(10);

		JButton QueryBt = new JButton("查詢");
		QueryBt.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (!QueryChinese.getText().isEmpty() || !QueryTxt.getText().isEmpty()) {
					Resault.setText("");
					ChahwaGetQuery GetQuery = new ChahwaGetQuery();
					GetQuery.setDrug(QueryChinese.getText());
					GetQuery.setHid(QueryTxt.getText());
					new Thread(GetQuery).start();
				} else {
					JOptionPane.showMessageDialog(null, "沒有輸入");
				}
			}
		});
		QueryBt.setBounds(291, 16, 87, 23);
		frame.getContentPane().add(QueryBt);
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 120, 414, 132);
		frame.getContentPane().add(scrollPane);
		Resault.setEditable(false);
		scrollPane.setViewportView(Resault);
		JLabel label_1 = new JLabel("查詢結果");
		label_1.setBounds(10, 100, 87, 15);
		frame.getContentPane().add(label_1);

		JLabel label = new JLabel("藥品名稱：");
		label.setFont(new Font("新細明體", Font.PLAIN, 12));
		label.setBounds(10, 50, 68, 15);
		frame.getContentPane().add(label);

		QueryChinese = new JTextField();
		QueryChinese.setColumns(10);
		QueryChinese.setBounds(78, 50, 179, 21);
		frame.getContentPane().add(QueryChinese);
		frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent e) {
				frame.dispose();
			}
		});
	}
}
